<?php

namespace app\common\model\message;

use app\common\model\User;
use app\common\model\UserGroup;
use think\Model;


class Category extends Model
{

    // 表名
    protected $name = 'message_category';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'group_text',
        'users_text',
    ];

    public function getGroupTextAttr($value, $data)
    {
        $array = UserGroup::whereIn('id', $data['group_ids'])->column('name');
        if ($array) {
            return implode(',', $array);
        }
        return '';
    }
    
    public function getUsersTextAttr($value, $data)
    {
        $array = User::whereIn('id', $data['firm_ids'])->column('nickname');
        if ($array) {
            return implode(',', $array);
        }
        return '';
    }
}
